package com.example.bigdata.scala.For遍历

object ForDemo {
    def main(args: Array[String]): Unit = {
        val dogBreeds = List("D", "Y", "D", "S", "G", "P")
        for (breed <- dogBreeds)
            println(breed)
        //生成器表达式
        for (i <- 1 to 10) println(i)

        //约束: 过滤值
        for (breed <- dogBreeds if breed.contains("D")){
            println(breed)
        }

        for (breed <- dogBreeds
             if breed.contains("D")
             if  !breed.startsWith("Y")
        ) println(breed)

        for (breed <- dogBreeds
             if breed.contains("D") &&  !breed.startsWith("Y")
        ) println(breed)

        //在Scala的for表达式中，我们可以使用yield关键字来生成新的集合。
        val dogBreeds1 = List("D", "Y", "D", "S", "G", "P")

    }
}
